/* 
 * @author wxj
 * @version 1.4
 * ���ܣ��û��޸�
 * 2006-12-27
 */

package com.zjht.gmcc.servlet.sys;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;


public class OperEdit extends BaseServlet {

	private static final long serialVersionUID = 1L;


	public boolean process(HttpServletRequest request, HttpServletResponse response,HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)throws Exception {
		int i_flag = 0;

		String s_username = request.getParameter("username");
		String s_usercode = request.getParameter("usercode");
		String s_deptid_dutyid = request.getParameter("deptid_dutyid");
		String operid = request.getParameter("operid");

		String[] ssarr = s_deptid_dutyid.split("#");
		String s_deptid = ssarr[0];
		String s_dutyid = ssarr[1];

		String s_tel = request.getParameter("tel");
		String s_email = request.getParameter("email");
		String s_status = (request.getParameter("status") == null) ? "0" : request
				.getParameter("status");

		PreparedStatement ps = null;

		String s_sql = "update opers set opername=?,deptid=?,telephone=?,email=?,status=?"
				+ ("1".equals(s_status) ? "" : ",stopdate=SYSDATE") + " where operid=?";
		ps = myJDBC.prepareStatement(s_sql);
		ps.setString(1, s_username);
		ps.setString(2, s_deptid);
		ps.setString(3, s_tel);
		ps.setString(4, s_email);
		ps.setString(5, s_status);
		ps.setString(6, operid);

		i_flag = ps.executeUpdate();

		ps.close();
		ps = null;

		if (i_flag == 1) {
			s_sql = "update operspopedom set dutyid=? where operid=?";
			ps = myJDBC.prepareStatement(s_sql);
			ps.setString(1, s_dutyid);
			ps.setString(2, operid);
			i_flag = ps.executeUpdate();
			s_sql = null;
			ps.close();
			ps = null;
		}

		String act = "用户信息";
		if (i_flag > 0) {
			alertAndReturnValue(out,act + "成功", "1");
			
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return i_flag > 0;

	}
}
